<template>
  <div class="model-page">
    <!-- 头部操作栏 -->
    <div class="model-container">
      <!-- 模型视图 -->
      <div id="model" ref="model" @dragover.prevent>
        <div class="camera-icon">
          <el-tooltip effect="dark" content="居中" placement="top">
            <el-icon :size="18" color="#fff" @click="onResetCamera">
              <Aim />
            </el-icon>
          </el-tooltip>
        </div>
      </div>
    </div>
    <dv-border-box-7  class="overlay">dv-border-box-7</dv-border-box-7>
    <dv-border-box-7  class="overlay2">dv-border-box-7</dv-border-box-7>
    <dv-border-box-7  class="overlay3">dv-border-box-7</dv-border-box-7>
    <dv-border-box-7  class="overlay4">dv-border-box-7</dv-border-box-7>
    <dv-border-box-7  class="overlay5">dv-border-box-7</dv-border-box-7>
    <dv-border-box-7  class="overlay6">dv-border-box-7</dv-border-box-7>
    <dv-border-box-7  class="overlay7">dv-border-box-7</dv-border-box-7>
    <page-loading :loading="loading" :percentage="progress"></page-loading>
  </div>

</template>

<script setup name="modelEdit">
// import { ModelEditPanel, ModelChoose, DataConfig } from "@/components/index";
import { onMounted, ref, getCurrentInstance, onBeforeUnmount, computed } from "vue";
import { useRouter } from "vue-router";
import { ElMessage, ElMessageBox } from "element-plus";
import renderModel from "@/utils/renderModel";
import { modelList } from "@/config/model";
import PageLoading from "@/components/Loading/PageLoading";
import { MODEL_PRIVEW_CONFIG, MODEL_BASE_DATA, MODEL_DEFAULT_CONFIG } from "@/config/constant";
import { useMeshEditStore,useIndexedDBStore } from '@/store/meshEditStore'
// import RightConfig from "../RightConfig/index.vue";

const store = useMeshEditStore();
const router = useRouter();
const { $bus, $local } = getCurrentInstance().proxy;

const dialogVisible=ref(false);
const loading = ref(false);
const progress = ref(0);
const editPanel = ref(null);
const choosePanel = ref(null);
const fullscreenStatus = ref(false)

// 重置相机位置
const onResetCamera = () => {
  store.modelApi.onResetModelCamera();
};
// 初始化模型库数据
const initModelBaseData = () => {
  const modelBase = $local.get(MODEL_BASE_DATA);
  // 如果是首次加载需要设置模型库初始数据值
  if (!Array.isArray(modelBase)) {
    let modelBaseData = [];
    modelList.forEach((v) => {
      modelBaseData.push({
        ...MODEL_DEFAULT_CONFIG,
        fileInfo: { ...v },
      });
    });
    $local.set(MODEL_BASE_DATA, modelBaseData);
  }
};


// 全屏监听事件
const addEventListenerFllscreen = (e) => {
  const status = document.fullscreenElement || document.webkitFullscreenElement;
  fullscreenStatus.value = !!status
}

onMounted(async () => {
  loading.value = true;
  const modelApi = new renderModel("#model");
  store.setModelApi(modelApi)
  $bus.on("page-loading", (value) => {
    loading.value = value;

  });
  // 模型加载进度条
  store.modelApi.onProgress((progressNum) => {
    progress.value = Number((progressNum / 1024 / 1024).toFixed(2));
    // console.log('模型已加载' + progress.value + 'M')
  });
  const load = await modelApi.init();
  if (load) {
    loading.value = false;
    progress.value = 0;
  }
  // 初始化模型库数据
  initModelBaseData();
});

</script>
<!-- #010c1d -->
<style lang="scss" scoped>
.model-page {
  width: 100%;
  background-color: #1b1c23;

  .model-header {
    height: 56px;
    width: 100%;
    background-color: #ffffff;
    box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.1);
    text-align: center;
    font-weight: 500;
    border-bottom: 3px solid #000;
    color: #fff;
    text-shadow: 5px 3px 5px #c11212;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0px 10px;
    box-sizing: border-box;
  }

  .model-container {
    display: flex;
    /*width: 98.5vw;*/
    width: 100vw;
    #model {
      /*width: 1920px;
      height: 1080px;*/
      width: 100vw;
      height: 100vh;
      position: relative;

      .camera-icon {
        position: absolute;
        top: 10px;
        cursor: pointer;
      }
    }
  }
}
/*width: 60vw;
      height: calc(100vh - 35px);*/
</style>

<style lang="scss">
  body{
    overflow:hidden;
  }
.edit-box{
   height: calc(100vh - 79px);
}

.edit-box,
.model-choose {
  .header {
    width: 100%;
    height: 35px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #33343f;
    color: #ccc;
    padding: 0px 20px;
    border-bottom: 1px solid #1b1c23;
    border-top: 1px solid #1b1c23;
    box-sizing: border-box;
  }

  .disabled {
    opacity: 0.3;
    pointer-events: none;
  }

  .options {
    width: 19vw;
    box-sizing: border-box;
    background-color: #1b1c23;

    .option-active {
      background-color: #27282f;
    }

    .space-between {
      justify-content: space-between;
    }

    .option {
      padding: 0px 3px;
      box-sizing: border-box;
      cursor: pointer;
      color: #ccc;
      display: flex;
      align-items: center;
      height: 33px;
      font-size: 14px;

      .icon-name {
        display: flex;
        align-items: center;
      }
    }
  }
}

.el-input-number {
  width: 90px !important;
}
.overlay {
    position: absolute; /* 或者 relative/fixed，取决于你的布局需求 */
    top: 10%; /* 调整到你想要的位置 */
    left: 10px; /* 调整到你想要的位置 */
    z-index: 100; /* 确保这个值高于 canvas 的任何可能的 z-index 值 */
    padding: 10px;
    width: 20%;
    height: 25%
}
.overlay2 {
    position: absolute; /* 或者 relative/fixed，取决于你的布局需求 */
    top: calc(35% + 30px); /* 调整到你想要的位置 */
    left: 10px; /* 调整到你想要的位置 */
    z-index: 100; /* 确保这个值高于 canvas 的任何可能的 z-index 值 */
    padding: 10px;
    width: 20%;
    height: 25%
}
.overlay3 {
    position: absolute; /* 或者 relative/fixed，取决于你的布局需求 */
    top: calc(60% + 60px); /* 调整到你想要的位置 */
    left: 10px; /* 调整到你想要的位置 */
    z-index: 100; /* 确保这个值高于 canvas 的任何可能的 z-index 值 */
    padding: 10px;
    width: 20%;
    height: 25%
}


.overlay4 {
    position: absolute; /* 或者 relative/fixed，取决于你的布局需求 */
    top: 10%; /* 调整到你想要的位置 */
    right: 10px; /* 调整到你想要的位置 */
    z-index: 100; /* 确保这个值高于 canvas 的任何可能的 z-index 值 */
    padding: 10px;
    width: 20%;
    height: 25%
}
.overlay5 {
    position: absolute; /* 或者 relative/fixed，取决于你的布局需求 */
    top: calc(35% + 30px); /* 调整到你想要的位置 */
    right: 10px; /* 调整到你想要的位置 */
    z-index: 100; /* 确保这个值高于 canvas 的任何可能的 z-index 值 */
    padding: 10px;
    width: 20%;
    height: 25%
}
.overlay6 {
    position: absolute; /* 或者 relative/fixed，取决于你的布局需求 */
    top: calc(60% + 60px); /* 调整到你想要的位置 */
    right: 10px; /* 调整到你想要的位置 */
    z-index: 100; /* 确保这个值高于 canvas 的任何可能的 z-index 值 */
    padding: 10px;
    width: 20%;
    height: 25%
}

.overlay7 {
    position: absolute; /* 或者 relative/fixed，取决于你的布局需求 */
    top: 70%; /* 调整到你想要的位置 */
    left: calc(20% + 40px); /* 调整到你想要的位置 */
    z-index: 100; /* 确保这个值高于 canvas 的任何可能的 z-index 值 */
    padding: 10px;
    width: calc(60% - 100px);
    height: 25%
}

/*.leftleft{
  overflow: hidden;
  width: 19.8vw;
  height: 100vh
}
.left{
  overflow-y:auto;
  width: 22vw;
  height: 100vh
}*/
/*
.left{
  overflow-x :hidden;
  overflow-y:hidden;
  scrollbar-width:1px;
  height: calc(100vh - 10px)
}
.left:hover{
  overflow-y:overlay;
  margin-right: calc(100% - 100vw);
}
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
}
::-webkit-scrollbar-thumb {
  background-color: darkgrey;
  outline: 1px solid slategrey;
}*/
</style>
